package org.eden.heartbeat.api.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Entity that represents a period where the remote machine was offline.
 *
 * @author trsimoes
 * @version $Revision:$
 */
public class OfflinePeriod {

    private List<Request> reports = new ArrayList<Request>();

    public void addReport(Request request) {
        reports.add(request);
    }

    public List<Request> getReports() {
        return reports;
    }

    public void setReports(List<Request> reports) {
        this.reports = reports;
    }

    public long getTotalOfflineTime() {
        long offlineTime = 0;
        Request tmp = null;
        for (Request request : this.reports) {
            if (tmp == null) {
                tmp = request;
            } else {
                long tmpMillis = tmp.getDate().getTime();
                long reportDataMillis = request.getDate().getTime();
                offlineTime += (reportDataMillis - tmpMillis);
                tmp = request;
            }
        }

        return offlineTime;
    }
}